#ifdef _DEBUG
bool st;
#endif
#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
    int f = 0, ans = 0;
    char c = getchar();
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        ans = (ans << 3) + (ans << 1) + c - 48, c = getchar();
    return f ? -ans : ans;
}
void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void printws(int x, char ch = ' ')
{
    write(x);
    putchar(ch);
}
inline void println(int x)
{
    write(x);
    putchar('\n');
}
constexpr int N = 1e6 + 5;
int n, m;
int T, mx;
string a[N], res[N];
auto IF(int i, int j)
{
    return 0 < i && i <= n &&
           0 <= j && j < m &&
           a[i][j] == '#';
}
auto dir(int i, int j, int t)
{
    int v = ((i % 5 + 5) % 5 + (2 * (j % 5 + 5) % 5)) % 5;
    v = (v + t) % 5;
    return v;
}
#ifdef _DEBUG
bool ed;
#endif
signed main()
{
#ifdef _DEBUG
    cerr << "MEM USE: " << (&ed - &st) / 1e6 << " MB" << endl;
#endif
#ifndef LOCAL
    freopen("indian.in", "r", stdin);
    freopen("indian.out", "w", stdout);
#endif
    // n = read(), m = read();
    // for (int i = 0; i < n; ++i)
    //     a[i] = read();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    mx = 1e18;
    for (int t = 0; t <= 4; ++t)
    {
        int x = 0, y = 0;
        for (int i = 1; i <= n; ++i)
            for (int j = 0; j < m; ++j)
                if (a[i][j] == '#')
                {
                    int rd = dir(i, j, t);
                    if (rd == 0)
                    {
                        ++x;
                        continue;
                    }
                    int nxi = i, nxj = j;
                    if (rd == 1)
                        nxi = i - 1, nxj = j;
                    else if (rd == 4)
                        nxi = i + 1, nxj = j;
                    else if (rd == 2)
                        nxi = i, nxj = j - 1;
                    else if (rd == 3)
                        nxi = i, nxj = j + 1;
                    y += !IF(nxi, nxj);
                }
        if (x + y < mx)
            mx = x + y, T = t;
    }
    for (int i = 1; i <= n; ++i)
        res[i] = string(m, '.');
    for (int i = 1; i <= n; ++i)
        for (int j = 0; j < m; ++j)
            if (a[i][j] == '#')
            {
                int s = dir(i, j, T);
                if (s == 0)
                {
                    res[i][j] = '1';
                    continue;
                }
                int nxi = i, nxj = j;
                if (s == 1)
                    nxi = i - 1, nxj = j;
                else if (s == 4)
                    nxi = i + 1, nxj = j;
                else if (s == 2)
                    nxi = i, nxj = j - 1;
                else if (s == 3)
                    nxi = i, nxj = j + 1;
                res[i][j] = IF(nxi, nxj) ? '0' : '1';
            }
    for (int i = 1; i <= n; ++i)
        cout << res[i] << '\n';
    return 0;
}
